package com.manbu.live.farmework.datasource.config;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.google.common.base.Preconditions;
import com.sun.security.auth.login.ConfigFile;
import org.apache.commons.lang3.StringUtils;
import org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereDriverURLProvider;
import org.springframework.core.convert.Property;

import java.nio.charset.StandardCharsets;
import java.util.Properties;

/**
 * @author hanWang
 * @Title:
 * @Package
 * @Description:
 * @date 2024/1/274:07 AM
 */
public class NacosDriverURLProvider implements ShardingSphereDriverURLProvider {
    private static final String NACOS_TYPE = "nacos:";

    public NacosDriverURLProvider() {
    }

    public boolean accept(String url) {

        return StringUtils.isNotBlank(url) && url.contains(NACOS_TYPE);
    }

    public byte[] getContent(String url) {
        ConfigService configService = null;
        String resultConfig = "";
        try {


            Properties properties = new Properties();
            properties.put(PropertyKeyConst.SERVER_ADDR,"49.232.243.152:8848");
            properties.put(PropertyKeyConst.USERNAME,"nacos");
            properties.put(PropertyKeyConst.PASSWORD,"nacos");
            properties.put(PropertyKeyConst.NAMESPACE,"2971f36f-c8fb-4b54-8423-a130f3513b9f");
            configService = NacosFactory.createConfigService(properties);
            resultConfig = configService.getConfig("mb-live-user-shardingjdbc.yaml", "DEFAULT_GROUP", 6000);

        } catch (Exception e){

        }
       return resultConfig.getBytes();
    }

    public static void main(String[] args) {


    }
}
